;;==========================================================================
;; Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
;;==========================================================================

#include "syscallno.h"

    AREA |.text|, ALIGN=2, CODE, READONLY

    MACRO
    $SyscallName SyscallArgBelow5 $syscallNum
    EXPORT  $SyscallName
$SyscallName
    mov     ip, sp
    stmdb   sp!, {r5, fp, ip, lr}
    mov     fp, ip

    mov     r5, #0x0
    swi     $syscallNum

    ldmdb	fp, {r5, fp, sp, pc}
    MEND


    MACRO
    $SyscallName SyscallArg5 $syscallNum
    EXPORT  $SyscallName
$SyscallName
    mov     ip, sp
    stmdb   sp!, {r4, r5, fp, ip, lr}
    mov     fp, ip

    ldr     r4, [fp]
    mov     r5, #0x0
    swi     $syscallNum

    ldmdb	fp, {r4, r5, fp, sp, pc}
    MEND

#define DO_SYSCALL_0(name, no) \
name SyscallArgBelow5 no

#define DO_SYSCALL_1(name, no) \
name SyscallArgBelow5 no

#define DO_SYSCALL_2(name, no) \
name SyscallArgBelow5 no

#define DO_SYSCALL_3(name, no) \
name SyscallArgBelow5 no

#define DO_SYSCALL_4(name, no) \
name SyscallArgBelow5 no

#define DO_SYSCALL_5(name, no) \
name SyscallArg5 no


//SYSCALLAPI ECode SysPrint(const wchar_t * pwszMsg)
DO_SYSCALL_1(SysPrint, CALLNO_SYS_PRINT)


//SYSCALLAPI ECode SysGetMemtraceArgs(wchar_t *pwchArgId, UInt32 *pIndex, \
//                                    Address *pWatchAddr)
DO_SYSCALL_3(SysGetMemtraceArgs, CALLNO_SYS_GETMEMTRACEARGS)


//SYSCALLAPI ECode SysBreak(uint_t uAddr)
DO_SYSCALL_1(SysBreak, CALLNO_SYS_BREAK)


//SYSCALLAPI ECode SysRegister(IStub *pIStub, CLSID *pCLSID, IID * pIID, \
//                             oid_t *pOid, CIClassEntry ** ppClsInfo)
DO_SYSCALL_5(SysRegister, CALLNO_SYS_REGISTER)


//SYSCALLAPI ECode SysUnregister(oid_t oid)
DO_SYSCALL_1(SysUnregister, CALLNO_SYS_UNREGISTER)


//SYSCALLAPI ECode SysRegisterCommon(const wchar_t * pwszName, \
//            IStub * pIStub, CLSID * pCLSID, IID * pIID,\
//            oid_t * pRet, CIClassEntry ** ppClsInfo)
    EXPORT SysRegisterCommon
SysRegisterCommon
    mov     ip, sp
    stmdb   sp!, {r4, r5, fp, ip, lr}
    mov     fp, ip
    sub     sp, sp, #8

    sub     r5, fp, #28
    str     r2, [r5]
    str     r3, [r5, #4]
    mov     r2, r5
    ldr     r3, [fp]
    ldr     r4, [fp, #4]

    mov     r5, #0x0
    swi     CALLNO_SYS_REGISTER_COMMON

    ldmdb	fp, {r4, r5, fp, sp, pc}


//SYSCALLAPI ECode SysResolveCommon(const wchar_t * pwszName, oid_t * pRet, \
//                      CLSID *pClsid, UInt32 *puIndex, CIClassEntry ** ppClsInfo, \
//                      PContext * ppContext)
    EXPORT SysResolveCommon
SysResolveCommon
    mov     ip, sp
    stmdb   sp!, {r4, r5, fp, ip, lr}
    mov     fp, ip
    sub     sp, sp, #8

    sub     r5, fp, #28
    ldr     r4, [fp]
    str     r4, [r5]
    ldr     r4, [fp, #4]
    str     r4, [r5, #4]
    mov     r4, r5

    mov     r5, #0x0
    swi     CALLNO_SYS_RESOLVE_COMMON

    ldmdb	fp, {r4, r5, fp, sp, pc}


//SYSCALLAPI ECode SysUnregisterCommon(const wchar_t * pwszName)
DO_SYSCALL_1(SysUnregisterCommon, CALLNO_SYS_UNREGISTER_COMMON)


//SYSCALLAPI ECode SysInvoke(oid_t oid, bool_t async, void *pvInBuf,
//            size_t uInBufSize, void *pvOutBuf, size_t uOutBufSize)
    EXPORT SysInvoke
SysInvoke
    mov     ip, sp
    stmdb   sp!, {r4, r5, fp, ip, lr}
    mov     fp, ip
    sub     sp, sp, #8

    sub     r5, fp, #28
    str     r0, [r5]
    str     r1, [r5, #4]
    mov     r0, r5
    mov     r1, r2
    mov     r2, r3
    ldr     r3, [fp]
    ldr     r4, [fp, #4]

    mov     r5, #0x0
    swi     CALLNO_SYS_INVOKE

    ldmdb	fp, {r4, r5, fp, sp, pc}


//SYSCALLAPI ECode SysReply(ECode ec, void *pvOutBuf, size_t uOutBufSize)
DO_SYSCALL_3(SysReply, CALLNO_SYS_REPLY)


//SYSCALLAPI ECode SysRegisterClassInfo(CIClassInfo * pClassInfo)
DO_SYSCALL_1(SysRegisterClassInfo, CALLNO_SYS_REGISTER_CLASS_INFO);


//SYSCALLAPI ECode SysGetClassInfo(CLSID *pClsid, CIClassEntry **ppClassInfo)
DO_SYSCALL_2(SysGetClassInfo, CALLNO_SYS_GET_CLASS_INFO)


//SYSCALLAPI ECode SysExitThread(/* [in] */ ECode exitCode)
DO_SYSCALL_1(SysExitThread, CALLNO_SYS_EXIT_THREAD)


//SYSCALLAPI ECode SysRegisterService(const wchar_t * pwszName, OID oid)
DO_SYSCALL_2(SysRegisterService, CALLNO_SYS_REGISTER_SERVICE)


//SYSCALLAPI ECode SysWaitService(const wchar_t * pwszName, Int32 msTimeout)
DO_SYSCALL_2(SysWaitService, CALLNO_SYS_WAIT_SERVICE)


//SYSCALLAPI ECode SysAttachServer(OID oid, PContext pContext)
DO_SYSCALL_2(SysAttachServer, CALLNO_SYS_ATTACH_SERVER)


//SYSCALLAPI ECode SysDetachServer(OID oid, PContext pContext)
DO_SYSCALL_2(SysDetachServer, CALLNO_SYS_DETACH_SERVER)


//SYSCALLAPI ECode SysCreateEvent(HANDLE *pEventHandle)
DO_SYSCALL_1(SysCreateEvent, CALLNO_SYS_CREATE_EVENT)

//SYSCALLAPI ECode SysDestroyEvent(HANDLE eventHandle)
DO_SYSCALL_1(SysDestroyEvent, CALLNO_SYS_DESTROY_EVENT)



//SYSCALLAPI ECode SysNotifyEvent(HANDLE eventHandle)
DO_SYSCALL_1(SysNotifyEvent, CALLNO_SYS_NOTIFY_EVENT)


//SYSCALLAPI ECode SysWaitEvent(HANDLE eventHandle)
DO_SYSCALL_1(SysWaitEvent, CALLNO_SYS_WAIT_EVENT)


//SYSCALLAPI ECode SysSetBreakPoint(
//        UInt32 uNo, BreakPointType type, void *pvAddress, UInt32 uLength)
DO_SYSCALL_4(SysSetBreakPoint, CALLNO_SYS_SET_BREAKPOINT)


//SYSCALLAPI ECode SysGetVirtualCode(struct KBDStatus *pVirtulCode)
DO_SYSCALL_1(SysGetVirtualCode, CALLNO_SYS_GETVIRTUALCODE)


//SYSCALLAPI ECode SysReboot()
DO_SYSCALL_0(SysReboot, CALLNO_SYS_SYSREBOOT)


//SYSCALLAPI ECODE SysSleep(int ms, WaitResult *pResult)
DO_SYSCALL_2(SysSleep, CALLNO_SYS_SLEEP)

//SYSCALLAPI ECode SysSendToKernel(UInt32 *buf, UInt32 type)
DO_SYSCALL_2(CALLNO_SYS_SendToKernel, buf, type)


    END